Caching Overview
This document describes the caching strategy in ValkyrAI backend for performance and safety.
Goals
- Reduce repeated ACL and SID lookups on hot paths.
- Keep permission decisions fresh with micro‑TTL caching.
- Avoid distributed state until measured; enable upgrade path to Redis later.
What’s Implemented
- Ehcache 3 (JCache) as in‑process cache provider.
- Spring Cache wired via
JCacheCacheManagerinvalkyrai/src/main/java/com/valkyrlabs/valkyrai/config/CachingConfig.java:1. - Caches and TTLs:
sidByUsername: 30m TTL, cachesAclSidby username/authority.permissionDecisions: 15s TTL, cachesAclService.hasPermission(...)results.- Existing caches kept:
aclCache,entityCache,entityListCache,entityPageCache.
Hot Path Details
AclSidLookupService.findFirstBySid(String): annotated with@Cacheable("sidByUsername"), used byAclServicefor SID ID resolution and anonymous lookups.AclService.hasPermission(ObjectIdentity, String, Permission): annotated with@Cacheable("permissionDecisions")and evicted on write operations that could affect permissions.
Eviction
createAcl,updateAcl,grantPermission,revokePermissionnow evictpermissionDecisions(andaclCachewhere appropriate) to prevent stale authorization.
Logging
KMSSecureFieldAspectlogging level set to WARN inapplication.yamlto reduce noise in production.
Future: Distributed Caching
- If/when needed, introduce Redis for coarse‑grained caches (e.g., read‑only lists), keeping permission decisions local. Minimal code changes required since Spring Cache abstractions are used.